import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'sqflite_helper_platform_interface.dart';

/// An implementation of [SqfliteHelperPlatform] that uses method channels.
class MethodChannelSqfliteHelper extends SqfliteHelperPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('sqflite_helper');

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<bool> pathExist(String path) async {
    final exist = await methodChannel.invokeMethod<bool>('pathExist', {"path": path}) ?? false;
    return exist;
  }

  @override
  Future<void> makeDir(String path) async {
    await methodChannel.invokeMethod<void>('makeDir', {"path": path});
  }

  @override
  Future<void> writeDataToFile({required String path, required List<int> bytes}) async {
    await methodChannel.invokeListMethod<int>('writeDataToFile', {'path': path, 'data': bytes});
  }
}
